package com.gzw.jackyweather;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.gzw.jackyweather.db.Skin;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

public class SplashActivity extends AppCompatActivity {


    private List<Skin> skins;

    private int[] imgIds = {R.mipmap.skin2, R.mipmap.skin3, R.mipmap.skin4
            , R.mipmap.skin5, R.mipmap.skin6, R.mipmap.skin7};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        skins = new ArrayList<>();

        skins.addAll(DataSupport.findAll(Skin.class));

        //第一次保存所有主题
        if (skins.size() == 0) {
            for (int i = 0; i < imgIds.length; i++) {
                Skin skin = new Skin();
                skin.setImgId(imgIds[i]);
                if (i == 0) {
                    skin.setDefault(true);
                } else {
                    skin.setDefault(false);
                }
                skin.setFlag("id");
                skin.save();
            }
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1500);
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}